(function() {
    'use strict';

    angular
        .module('milkbeeApp')
        .config(stateConfig);

    stateConfig.$inject = ['$stateProvider'];

    function stateConfig($stateProvider) {
        $stateProvider
        .state('sweepstake', {
            parent: 'entity',
            url: '/sweepstake?page&sort&search',
            data: {
                authorities: ['ROLE_ADMIN'],
                pageTitle: 'milkbeeApp.sweepstake.home.title'
            },
            views: {
                'content@': {
                    templateUrl: 'app/entities/sweepstake/sweepstakes.html',
                    controller: 'SweepstakeController',
                    controllerAs: 'vm'
                }
            },
            params: {
                page: {
                    value: '1',
                    squash: true
                },
                sort: {
                    value: 'id,asc',
                    squash: true
                },
                search: null
            },
            resolve: {
                pagingParams: ['$stateParams', 'PaginationUtil', function ($stateParams, PaginationUtil) {
                    return {
                        page: PaginationUtil.parsePage($stateParams.page),
                        sort: $stateParams.sort,
                        predicate: PaginationUtil.parsePredicate($stateParams.sort),
                        ascending: PaginationUtil.parseAscending($stateParams.sort),
                        search: $stateParams.search
                    };
                }],
                translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
                    $translatePartialLoader.addPart('sweepstake');
                    $translatePartialLoader.addPart('award');
                    $translatePartialLoader.addPart('global');
                    return $translate.refresh();
                }]
            }
        })
        .state('sweepstake-detail', {
            parent: 'entity',
            url: '/sweepstake/{id}',
            data: {
                authorities: ['ROLE_ADMIN'],
                pageTitle: 'milkbeeApp.sweepstake.detail.title'
            },
            views: {
                'content@': {
                    templateUrl: 'app/entities/sweepstake/sweepstake-detail.html',
                    controller: 'SweepstakeDetailController',
                    controllerAs: 'vm'
                }
            },
            resolve: {
                translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
                    $translatePartialLoader.addPart('sweepstake');
                    return $translate.refresh();
                }],
                entity: ['$stateParams', 'Sweepstake', function($stateParams, Sweepstake) {
                    return Sweepstake.get({id : $stateParams.id}).$promise;
                }],
                previousState: ["$state", function ($state) {
                    var currentStateData = {
                        name: $state.current.name || 'sweepstake',
                        params: $state.params,
                        url: $state.href($state.current.name, $state.params)
                    };
                    return currentStateData;
                }]
            }
        })
        .state('sweepstake-detail.edit', {
            parent: 'sweepstake-detail',
            url: '/detail/edit',
            data: {
                authorities: ['ROLE_ADMIN']
            },
            onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
                $uibModal.open({
                    templateUrl: 'app/entities/sweepstake/sweepstake-dialog.html',
                    controller: 'SweepstakeDialogController',
                    controllerAs: 'vm',
                    backdrop: 'static',
                    size: 'lg',
                    resolve: {
                        entity: ['Sweepstake', function(Sweepstake) {
                            return Sweepstake.get({id : $stateParams.id}).$promise;
                        }]
                    }
                }).result.then(function() {
                    $state.go('^', {}, { reload: false });
                }, function() {
                    $state.go('^');
                });
            }]
        })
        .state('sweepstake.new', {
            parent: 'sweepstake',
            url: '/new',
            data: {
                authorities: ['ROLE_ADMIN']
            },
            onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
                $uibModal.open({
                    templateUrl: 'app/entities/sweepstake/sweepstake-dialog.html',
                    controller: 'SweepstakeDialogController',
                    controllerAs: 'vm',
                    backdrop: 'static',
                    size: 'lg',
                    resolve: {
                        entity: function () {
                            return {
                                name: null,
                                detail: null,
                                poster: null,
                                startAt: null,
                                endAt: null,
                                createdAt: null,
                                userId: null,
                                leaguerId: null,
                                id: null
                            };
                        }
                    }
                }).result.then(function() {
                    $state.go('sweepstake', null, { reload: 'sweepstake' });
                }, function() {
                    $state.go('sweepstake');
                });
            }]
        })
        .state('sweepstake-add-ward', {
        	parent: 'sweepstake',
        	url: '/{id}/sweepstakeaddward',
        	data: {
        		authorities: ['ROLE_ADMIN']
        	},
        	onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
        		$uibModal.open({
        			templateUrl: 'app/entities/sweepstake/sweepstake-award-dialog.html',
        			controller: 'SweepstakeAddWardDialogController',
        			controllerAs: 'vm',
        			backdrop: 'static',
        			size: 'lg',
        			resolve: {
        				entity: function () {
        					return {
        						name: null,
                                detail: null,
                                rank: '3',
                                sweepstakeId:parseInt($stateParams.id),
                                quantum: 1,
                                photograph: null,
                                createdAt: null,
                                userId: null,
                                leaguerId: null,
                                id: null
        					};
        				}
        			}
        		}).result.then(function() {
        			$state.go('sweepstake', null, { reload: 'sweepstake' });
        		}, function() {
        			$state.go('sweepstake');
        		});
        	}]
        })
        .state('sweepstake.edit', {
            parent: 'sweepstake',
            url: '/{id}/edit',
            data: {
                authorities: ['ROLE_ADMIN']
            },
            onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
                $uibModal.open({
                    templateUrl: 'app/entities/sweepstake/sweepstake-dialog.html',
                    controller: 'SweepstakeDialogController',
                    controllerAs: 'vm',
                    backdrop: 'static',
                    size: 'lg',
                    resolve: {
                        entity: ['Sweepstake', function(Sweepstake) {
                            return Sweepstake.get({id : $stateParams.id}).$promise;
                        }]
                    }
                }).result.then(function() {
                    $state.go('sweepstake', null, { reload: 'sweepstake' });
                }, function() {
                    $state.go('^');
                });
            }]
        })
        .state('sweepstake.delete', {
            parent: 'sweepstake',
            url: '/{id}/delete',
            data: {
                authorities: ['ROLE_ADMIN']
            },
            onEnter: ['$stateParams', '$state', '$uibModal', function($stateParams, $state, $uibModal) {
                $uibModal.open({
                    templateUrl: 'app/entities/sweepstake/sweepstake-delete-dialog.html',
                    controller: 'SweepstakeDeleteController',
                    controllerAs: 'vm',
                    size: 'md',
                    resolve: {
                        entity: ['Sweepstake', function(Sweepstake) {
                            return Sweepstake.get({id : $stateParams.id}).$promise;
                        }]
                    }
                }).result.then(function() {
                    $state.go('sweepstake', null, { reload: 'sweepstake' });
                }, function() {
                    $state.go('^');
                });
            }]
        });
    }

})();
